#include "modbus_register.h"
#include "ice_cream_driver.h"
#include "control_modes.h"
// 首页模块私有变量
static uint16_t sold_out_status = 0;         // 售罄状态
static uint16_t ice_cream_forming_ratio = 0; // 冰淇淋成型比例
static uint16_t stop = 0;                    // STOP状态
static uint16_t main_unit = 0;               // 主机状态
static uint16_t device_mode = 0;             // 设备模式

// 首页模块寄存器读取
uint16_t modbus_home_get(uint16_t address) {
    switch(address) {
        case REG_SOLD_OUT_STATUS:
            return sold_out_status;
        case REG_OPERATION_MODE:
            return control_get_current_mode();
        case REG_ICE_FORM_RATIO:
            return ice_cream_forming_ratio;
        case REG_STOP:
            return stop;
        case REG_MAIN_UNIT:
            return main_unit;
        case REG_DEVICE_MODE:
            return device_mode;
        default:
            return 0;
    }
}

// 首页模块寄存器写入
void modbus_home_set(uint16_t address, uint16_t value) {
    switch(address) {
        case REG_OPERATION_MODE:
            // 验证运行模式合法性
            control_switch_mode(value);
            break;
        case REG_STOP:
            break;
        case REG_RETURN_ORIGIN:
            axis_xz_homing();
            break;
        case REG_MAIN_UNIT:
            break;
        case REG_DEVICE_MODE:

            break;
        default:
            break;
    }
}
